﻿package tools;

public class RecurveDemo {

	public static void main(String[] args) {

		doubleNum(1234);
		System.out.println("age=" + increaseAge(5));
		toBinary(13, new StringBuffer());
		System.out.println();
	}

	// n,2n,4n...以此类推，知道结果大于5000
	public static void doubleNum(int num) {
		if (num < 5000) {
			doubleNum(num * 2);
		}
		System.out.println(num);
	}

	// 第一个人10岁，之后每个人比前一个大2岁
	public static int increaseAge(int num) {
		if (num == 1)
			return 10;
		return increaseAge(num - 1) + 2;
	}

	// 转成二进制
	public static void toBinary(int n, StringBuffer sbstr) {
		if (n / 2 != 0)
			toBinary(n / 2, sbstr);
		sbstr.append(n % 2);
		System.out.println(sbstr);
	}
}
